<html>
<head><meta charset="utf-8"><title>re-visiting placement new · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/re-visiting.20placement.20new.html">re-visiting placement new</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="186346810"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/re-visiting%20placement%20new/near/186346810" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/re-visiting.20placement.20new.html#186346810">(Jan 23 2020 at 00:32)</a>:</h4>
<p>Do any recent changes (<code>MaybeUninit</code>, raw references, maybe even <code>Pin</code>?) make implementing placement new more feasible nowadays?</p>



<a name="186347082"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/re-visiting%20placement%20new/near/186347082" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/re-visiting.20placement.20new.html#186347082">(Jan 23 2020 at 00:37)</a>:</h4>
<p>not really. What we need an optimisation that guarantees construction of data into a location and once we do have that you wouldn't need a separate function for this.</p>



<a name="186347268"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/re-visiting%20placement%20new/near/186347268" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/re-visiting.20placement.20new.html#186347268">(Jan 23 2020 at 00:40)</a>:</h4>
<p>Would such an optimization work in all cases, e.g. even for collections?</p>



<a name="186347593"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/re-visiting%20placement%20new/near/186347593" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/re-visiting.20placement.20new.html#186347593">(Jan 23 2020 at 00:47)</a>:</h4>
<p>It would have to if we wanted placement-in.</p>



<a name="186347646"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/re-visiting%20placement%20new/near/186347646" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/re-visiting.20placement.20new.html#186347646">(Jan 23 2020 at 00:48)</a>:</h4>
<p>The original placement in just relied on having a <code>*mut T</code> to put a <code>T</code> into</p>



<a name="186347662"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/re-visiting%20placement%20new/near/186347662" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/re-visiting.20placement.20new.html#186347662">(Jan 23 2020 at 00:48)</a>:</h4>
<p>the problem is that forcing an arbitrary expression to put its data directly into the pointer rather than onto stack is… non-trivial</p>



<a name="186347680"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/re-visiting%20placement%20new/near/186347680" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/re-visiting.20placement.20new.html#186347680">(Jan 23 2020 at 00:49)</a>:</h4>
<p>i.e. the problem is the right hand side, not the left hand one.</p>



<a name="186347778"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/re-visiting%20placement%20new/near/186347778" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/re-visiting.20placement.20new.html#186347778">(Jan 23 2020 at 00:50)</a>:</h4>
<p>(I think "guaranteed optimization" is sort of a contradiction in terms. Optimizations are definitionally about improving code in some ways while preserving as-if. If as-if is not preserved it is not an optimization.)</p>



<a name="186347798"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/re-visiting%20placement%20new/near/186347798" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/re-visiting.20placement.20new.html#186347798">(Jan 23 2020 at 00:50)</a>:</h4>
<p>right.</p>



<a name="186347826"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/re-visiting%20placement%20new/near/186347826" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/re-visiting.20placement.20new.html#186347826">(Jan 23 2020 at 00:51)</a>:</h4>
<p>Whatever guarantees we make have to, in my view, be backed up by operational semantics, but should also be simple enough to specify (for the spec) and understand (for users).</p>



<a name="186347836"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/re-visiting%20placement%20new/near/186347836" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/re-visiting.20placement.20new.html#186347836">(Jan 23 2020 at 00:51)</a>:</h4>
<p>rather than it being optimisation, we need a way to guarantee that we can make <code>*t = EXPR</code> put its result into the location pointed to by pointer for arbitrary EXPRs.</p>



<a name="186347857"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/re-visiting%20placement%20new/near/186347857" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/re-visiting.20placement.20new.html#186347857">(Jan 23 2020 at 00:52)</a>:</h4>
<p>and that’s… not feasible AFAICT anyway</p>



<a name="186347890"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/re-visiting%20placement%20new/near/186347890" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/re-visiting.20placement.20new.html#186347890">(Jan 23 2020 at 00:52)</a>:</h4>
<p>without changing how EXPRs work, which is what C++ did.</p>



<a name="186347914"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/re-visiting%20placement%20new/near/186347914" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/re-visiting.20placement.20new.html#186347914">(Jan 23 2020 at 00:53)</a>:</h4>
<p><span class="user-mention" data-user-id="123586">@nagisa</span> my understanding is that C++'s guarantees were not operational either</p>



<a name="186348003"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/re-visiting%20placement%20new/near/186348003" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/re-visiting.20placement.20new.html#186348003">(Jan 23 2020 at 00:55)</a>:</h4>
<p>I can’t think of an example that would disprove it, tbh</p>



<a name="186348018"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/re-visiting%20placement%20new/near/186348018" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/re-visiting.20placement.20new.html#186348018">(Jan 23 2020 at 00:55)</a>:</h4>
<p>disprove what?</p>



<a name="186348071"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/re-visiting%20placement%20new/near/186348071" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/re-visiting.20placement.20new.html#186348071">(Jan 23 2020 at 00:56)</a>:</h4>
<p>Disprove that their guarantees are operational.</p>



<a name="186348075"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/re-visiting%20placement%20new/near/186348075" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/re-visiting.20placement.20new.html#186348075">(Jan 23 2020 at 00:56)</a>:</h4>
<p>unless we’re talking about different things.</p>



<a name="186348113"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/re-visiting%20placement%20new/near/186348113" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/re-visiting.20placement.20new.html#186348113">(Jan 23 2020 at 00:57)</a>:</h4>
<p>I mean, yes it is true that C++ requires the programmer to write code in a very particular way if they want the guarantee, but once they do it, they have the guarantee.</p>



<a name="186348127"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/re-visiting%20placement%20new/near/186348127" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/re-visiting.20placement.20new.html#186348127">(Jan 23 2020 at 00:57)</a>:</h4>
<p>(whether people write their code that way is a different question altogether)</p>



<a name="186348793"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/re-visiting%20placement%20new/near/186348793" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/re-visiting.20placement.20new.html#186348793">(Jan 23 2020 at 01:08)</a>:</h4>
<p>At least for Rust, we would need a way to observe the difference with and without the guarantee</p>



<a name="186350594"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/re-visiting%20placement%20new/near/186350594" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/re-visiting.20placement.20new.html#186350594">(Jan 23 2020 at 01:45)</a>:</h4>
<p>Well, <code>box [0; 1_000_000]</code> is going to blow your stack, but with placement new won't, right?</p>



<a name="186350600"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/re-visiting%20placement%20new/near/186350600" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/re-visiting.20placement.20new.html#186350600">(Jan 23 2020 at 01:45)</a>:</h4>
<p>but maybe not the best example :)</p>



<a name="186351194"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/re-visiting%20placement%20new/near/186351194" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/re-visiting.20placement.20new.html#186351194">(Jan 23 2020 at 02:00)</a>:</h4>
<p>Does Miri have a concept of a stack in this sense?<br>
Using "stack overflow" as the observable distinction would also make this guarantee subject to the things already in the stack (in memory) and the size of the new allocation</p>



<a name="186351425"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/re-visiting%20placement%20new/near/186351425" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/re-visiting.20placement.20new.html#186351425">(Jan 23 2020 at 02:05)</a>:</h4>
<p>I'm not sure why being able to observe something (in the sense of being able to nail down that observation) would need to be in the spec. Loosely, I would expect that placement construction boils down to "space is not allocated by the compiler" or something along those lines -- i.e., that the compiler is not permitted to place values outside the region provided during the construction of the object.</p>



<a name="186351428"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/re-visiting%20placement%20new/near/186351428" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/re-visiting.20placement.20new.html#186351428">(Jan 23 2020 at 02:05)</a>:</h4>
<p>That might be too strict, I'm not sure.</p>



<a name="186353492"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/re-visiting%20placement%20new/near/186353492" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/re-visiting.20placement.20new.html#186353492">(Jan 23 2020 at 02:58)</a>:</h4>
<p>I don't think the spec should be specified in terms of a compilation model. Even the word "compiler" is suspect in the spec imo.</p>



<a name="186366169"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/re-visiting%20placement%20new/near/186366169" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/re-visiting.20placement.20new.html#186366169">(Jan 23 2020 at 08:04)</a>:</h4>
<p>It seems like a lot of it can be half-solved with maybeuninit if you're willing to write code that sticks to a convention</p>



<a name="186376765"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/re-visiting%20placement%20new/near/186376765" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/re-visiting.20placement.20new.html#186376765">(Jan 23 2020 at 10:46)</a>:</h4>
<p>The convention that is needed for this is a very invasive and painful one, where you can't use a ordinary expressions or APIs to produce a significant amount of data and instead have to rewrite all the code involved in producing the values you want to write them to the destination piecewise. This is hardly a solution for the placement problem, similar (though to a lesser extent) to how "write assembly" is hardly a solution for missed optimizations.</p>



<a name="186394649"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/re-visiting%20placement%20new/near/186394649" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/re-visiting.20placement.20new.html#186394649">(Jan 23 2020 at 14:41)</a>:</h4>
<p>C++'s guarantee are specifically about copy/move constructor elision: you can observe the difference because your constructor is not getting called. The C++ standard makes no guarantees on stack usage.</p>



<a name="186395127"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/re-visiting%20placement%20new/near/186395127" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/re-visiting.20placement.20new.html#186395127">(Jan 23 2020 at 14:47)</a>:</h4>
<p>I wonder if there's some tie-in to Pin's guarantees about movement that we could utilize. Nothing springs to mind though.</p>



<a name="186458107"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/re-visiting%20placement%20new/near/186458107" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/re-visiting.20placement.20new.html#186458107">(Jan 24 2020 at 02:40)</a>:</h4>
<p>I wonder if there is a way to specify it operationally via an asymptotic space efficiency argument, a la Clinger 1998. Unfortunately I don’t know if he still has a public copy on a website</p>



<a name="186458137"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/re-visiting%20placement%20new/near/186458137" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/re-visiting.20placement.20new.html#186458137">(Jan 24 2020 at 02:41)</a>:</h4>
<p><span class="user-mention" data-user-id="116083">@pnkfelix</span> <a href="https://citeseer.ist.psu.edu/viewdoc/download;jsessionid=0FA23CCE7E9A17539134E7CFCD0CC6A0?doi=10.1.1.50.4500&amp;rep=rep1&amp;type=pdf" target="_blank" title="https://citeseer.ist.psu.edu/viewdoc/download;jsessionid=0FA23CCE7E9A17539134E7CFCD0CC6A0?doi=10.1.1.50.4500&amp;rep=rep1&amp;type=pdf">https://citeseer.ist.psu.edu/viewdoc/download;jsessionid=0FA23CCE7E9A17539134E7CFCD0CC6A0?doi=10.1.1.50.4500&amp;rep=rep1&amp;type=pdf</a>?</p>



<a name="186458188"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/re-visiting%20placement%20new/near/186458188" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/re-visiting.20placement.20new.html#186458188">(Jan 24 2020 at 02:42)</a>:</h4>
<p>Good work!</p>



<a name="186468658"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/re-visiting%20placement%20new/near/186468658" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/re-visiting.20placement.20new.html#186468658">(Jan 24 2020 at 07:18)</a>:</h4>
<p><span class="user-mention" data-user-id="124289">@rkruppe</span> I'm not clear on how you think it is so invasive. Maybe you're not imagining the same thing as me?</p>
<p>You can get "pseudo placement new" with just additional methods added to exiting types. If you give all your types a function that takes <code>&amp;mut MaybeUninit&lt;Self&gt;</code> and initializes it, then you can construct in place. Of course, the biggest drawback is that you can't access the fields of MaybeUninit at all easily. The second biggest drawback is that it's unsafe as all get out, so there's that. The third problem is of course that adding one method for each type you want to support "pseudo placement new" with doesn't scale very well. I'm not saying that a language level change isn't necessary, but I think that you can get a lot of the desired effect with MaybeUninit and/or zeroed().</p>
<p>However, I also haven't had to do much with the "don't let it touch the stack" problem. In the cases that I've faced personally, you can just alloc_zeroed and turn the pointer into a Boxed array and call it a day. So maybe I don't even understand the problem properly.</p>



<a name="186482531"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/re-visiting%20placement%20new/near/186482531" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/re-visiting.20placement.20new.html#186482531">(Jan 24 2020 at 11:22)</a>:</h4>
<p>No, that's pretty much what I mean too. Except it isn't just one method per type, it's extra code per "way to move a value". For example, if you want to have two <code>Vec&lt;HugeStruct&gt;</code> and want to take the last element of one Vec and push it onto the other Vec with minimal moves (and stack usage), you don't just need a placement-aware variant of <code>Vec::push</code>, you also need to reimplement <code>Vec::pop</code> to place the popped value into the destination directly. Open-coded that might look something like this:</p>
<div class="codehilite"><pre><span></span>vec1.push_emplace(|dest| {
    dest.as_mut_ptr().copy_from(vec2.last_mut().unwrap());
    vec2.set_len(vec2.len() - 1);
});
</pre></div>


<p>In this example the blowup is not so terrible, but in general if you have a <code>big(complicated(expression()))</code> resulting in a large type <code>T</code>, you may end up having to rewrite <em>all</em> code transitively used by that expression to have an out-argument instead. Sometimes that is unavoidable anyway, but in many cases the compiler <em>ought</em> to be able to generate the right code by just writing the results of expressions directly into their eventual destination without any temporaries.</p>



<a name="187167568"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/re-visiting%20placement%20new/near/187167568" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/re-visiting.20placement.20new.html#187167568">(Feb 01 2020 at 16:19)</a>:</h4>
<p>I am not sure if "operational guarantees" is the right benchmark here... sounds to me more like designing an opsem that is simple to compile efficiently. that's like how we don't guarantee that <code>i + 1</code> is compiled to an addition instruction (plus potential overflow check) instead of something ridicolously inefficient.</p>



<a name="187210411"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/re-visiting%20placement%20new/near/187210411" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/re-visiting.20placement.20new.html#187210411">(Feb 02 2020 at 16:14)</a>:</h4>
<p>Depends on whether best-effort optimizations like any others are sought after or if it is stability guarantees. The latter would, in my view, require something operational. The former is "just" a quality of implementation matter which the compiler team can tweak (and regress, improve again, ...) as they see fit.</p>



<a name="187215227"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/re-visiting%20placement%20new/near/187215227" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/re-visiting.20placement.20new.html#187215227">(Feb 02 2020 at 18:40)</a>:</h4>
<p>The people who have spoken to me about this being a requirement at all usually speak as if it's a <em>hard</em> requirement. If you use the Placement New then the generated code <em>must</em> have the transformation applied.</p>
<p>Of course they could be exaggerating, but I think people want an absolute assurance.</p>



<a name="187217164"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/re-visiting%20placement%20new/near/187217164" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/re-visiting.20placement.20new.html#187217164">(Feb 02 2020 at 19:43)</a>:</h4>
<p>Yes, otherwise the code in question will just hit stack overflow 100% of the time.</p>



<a name="187217208"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/re-visiting%20placement%20new/near/187217208" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/re-visiting.20placement.20new.html#187217208">(Feb 02 2020 at 19:44)</a>:</h4>
<p>ain’t good enough if applying this pattern would just reduce the chance you get an overflow</p>



<a name="187247923"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/re-visiting%20placement%20new/near/187247923" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Elichai Turkel <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/re-visiting.20placement.20new.html#187247923">(Feb 03 2020 at 10:06)</a>:</h4>
<blockquote>
<p>Well, <code>box [0; 1_000_000]</code> is going to blow your stack, but with placement new won't, right?</p>
</blockquote>
<p>well this already works now (even when adding a zero).</p>
<p>I agree with <span class="user-mention" data-user-id="126931">@centril</span> I don't know of any language that promises if new placement will be directly on the heap, or even that it will be on the heap.<br>
I think we should do our best that the compiler will actually optimize it to be directly on the heap (ideally even without the <code>box</code> syntax) but not promise that.</p>



<a name="187262207"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/re-visiting%20placement%20new/near/187262207" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wodann <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/re-visiting.20placement.20new.html#187262207">(Feb 03 2020 at 13:37)</a>:</h4>
<p>Placement new (in C++) merely allows you to instantiate an object directly in the provided memory location. As such this is a hard guarantee that no additional memory allocations will be used (no matter whether the provided memory location is on the heap or on the stack).  [search for placement new in <a href="https://en.cppreference.com/w/cpp/language/new" target="_blank" title="https://en.cppreference.com/w/cpp/language/new">https://en.cppreference.com/w/cpp/language/new</a> ]</p>



<a name="187263715"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/re-visiting%20placement%20new/near/187263715" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> kennytm <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/re-visiting.20placement.20new.html#187263715">(Feb 03 2020 at 13:56)</a>:</h4>
<p>IMO if you can guarantee that <code>box Struct { fields }</code>, <code>box Struct(fields)</code> (including <code>Enum::Variant(fields)</code>) and <code>box [x; n]</code> will not blow up the stack it already covers 99% use case of placement new</p>



<a name="187264419"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/re-visiting%20placement%20new/near/187264419" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/re-visiting.20placement.20new.html#187264419">(Feb 03 2020 at 14:04)</a>:</h4>
<p><code>box</code> is equivalent to what <code>HEAP &lt;- expr</code> was with the removed placement new.</p>



<a name="187264459"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/re-visiting%20placement%20new/near/187264459" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/re-visiting.20placement.20new.html#187264459">(Feb 03 2020 at 14:05)</a>:</h4>
<p>As thus it shares all of the caveats.</p>



<a name="187264667"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/re-visiting%20placement%20new/near/187264667" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> kennytm <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/re-visiting.20placement.20new.html#187264667">(Feb 03 2020 at 14:07)</a>:</h4>
<p>you know how it should generalize to <code>&lt;-</code> <span aria-label="upside down" class="emoji emoji-1f643" role="img" title="upside down">:upside_down:</span> i don't think it worth the effort to guarantee for arbitrary <code>expr</code></p>



<a name="187264759"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/re-visiting%20placement%20new/near/187264759" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> kennytm <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/re-visiting.20placement.20new.html#187264759">(Feb 03 2020 at 14:08)</a>:</h4>
<p>if someone writes <code>box f(x)</code> (<code>HEAP &lt;- f(x)</code>), i don't think we can avoid occupying the stack</p>



<a name="187264971"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/re-visiting%20placement%20new/near/187264971" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/re-visiting.20placement.20new.html#187264971">(Feb 03 2020 at 14:10)</a>:</h4>
<p>We could guarantee it for at least <code>extern "Rust"</code> stuff  if we adapt ABI (to e.g. always make caller allocate location for return values)</p>



<a name="187264997"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/re-visiting%20placement%20new/near/187264997" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/re-visiting.20placement.20new.html#187264997">(Feb 03 2020 at 14:11)</a>:</h4>
<p>but if we do that, we no longer need a separate syntax for this</p>



<a name="187266093"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/re-visiting%20placement%20new/near/187266093" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> kennytm <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/re-visiting.20placement.20new.html#187266093">(Feb 03 2020 at 14:22)</a>:</h4>
<blockquote>
<p>but if we do that, we no longer need a separate syntax for this</p>
</blockquote>
<p>you mean <code>vec.push(f(x))</code> would be made equivalent to <code>vec &lt;- f(x)</code> with such ABI?</p>



<a name="187269036"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/re-visiting%20placement%20new/near/187269036" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/re-visiting.20placement.20new.html#187269036">(Feb 03 2020 at 14:57)</a>:</h4>
<p>well, not that.</p>



<a name="187269048"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/re-visiting%20placement%20new/near/187269048" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/re-visiting.20placement.20new.html#187269048">(Feb 03 2020 at 14:57)</a>:</h4>
<p>because that introduces a semantic difference in operation</p>



<a name="187269078"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/re-visiting%20placement%20new/near/187269078" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/re-visiting.20placement.20new.html#187269078">(Feb 03 2020 at 14:57)</a>:</h4>
<p>/me takes everything back and throws it into the pit</p>



<a name="187269179"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/re-visiting%20placement%20new/near/187269179" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/re-visiting.20placement.20new.html#187269179">(Feb 03 2020 at 14:58)</a>:</h4>
<p>but that ABI particularity is a precondition for <code>vec &lt;- f(x)</code> to work reliably if at all</p>



<a name="187290150"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/re-visiting%20placement%20new/near/187290150" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/re-visiting.20placement.20new.html#187290150">(Feb 03 2020 at 18:32)</a>:</h4>
<p>The ABI changes necessary to make <code>place &lt;- f(x)</code> work as intended (modulo whatever happens inside of <code>f</code>) are actually another good reason to not pursue a strict guarantee of "no moves" (however this is formalized) but treat it as a QoI matter. A function returning e.g . an int should obviously be able to return it by value. Direct emplacement of return values is only useful for large types, where "large" is somewhat vague but certainly past the point where a "write the result through this out-pointer" ABI is desired anyway =&gt; we don't really need ABI changes, just RVO exploiting the existing ABI.</p>



<a name="187290604"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/re-visiting%20placement%20new/near/187290604" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/re-visiting.20placement.20new.html#187290604">(Feb 03 2020 at 18:37)</a>:</h4>
<p>More generally, making this a QoI matter <em>and being good enough at it</em> (much more consistent than we are today) shouldn't really make a difference vs. a hard guarantee for people worried about blowing up their stack: many other things that affect stack usage (e.g. amount of inlining, effectiveness of stack coloring, spills during register allocation) are also not guaranteed, but in practice these are rarely pathological enough to cause stack overflows and when they do it's often due to bugs we'd want to fix anyway. I'd like us to get to the same point with carefully-written Rust: if you adhere to a few conventions while constructing large objects in otherwise natural ways (i.e., not rewriting everything to have explicit out-pointers), the stack should not blow up unless a whole sequence of very unlikely things happened.</p>



<a name="187301484"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/re-visiting%20placement%20new/near/187301484" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/re-visiting.20placement.20new.html#187301484">(Feb 03 2020 at 20:39)</a>:</h4>
<blockquote>
<p>The people who have spoken to me about this being a requirement at all usually speak as if it's a <em>hard</em> requirement. If you use the Placement New then the generated code <em>must</em> have the transformation applied.</p>
<p>Of course they could be exaggerating, but I think people want an absolute assurance.</p>
</blockquote>
<p>I bet the same people say it is a <em>hard</em> requirement that <code>i+j</code> doesnt use up 1MB of stack space</p>



<a name="187301559"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/re-visiting%20placement%20new/near/187301559" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/re-visiting.20placement.20new.html#187301559">(Feb 03 2020 at 20:40)</a>:</h4>
<p>and yet our spec says nothing like that, and it would be very hard to make it do that (lets get a spec first before making it awesome like that)</p>



<a name="187301569"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/re-visiting%20placement%20new/near/187301569" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/re-visiting.20placement.20new.html#187301569">(Feb 03 2020 at 20:40)</a>:</h4>
<p>so, I dont see how focusing on a "hard operational requirement" is helping the slightest here</p>



<a name="187301589"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/re-visiting%20placement%20new/near/187301589" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/re-visiting.20placement.20new.html#187301589">(Feb 03 2020 at 20:40)</a>:</h4>
<p>what matters is that <em>in practice</em>, the compiler will never make the stack blow</p>



<a name="187301610"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/re-visiting%20placement%20new/near/187301610" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/re-visiting.20placement.20new.html#187301610">(Feb 03 2020 at 20:41)</a>:</h4>
<p>just like <em>in practice</em>, the compiler wont do ridiculous things with additions</p>



<a name="187301653"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/re-visiting%20placement%20new/near/187301653" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/re-visiting.20placement.20new.html#187301653">(Feb 03 2020 at 20:41)</a>:</h4>
<p>I agree though that "the compiler can <em>probably</em> optimize this" is <em>not</em> good enough -- it needs to be structural, as easy as it is to compile addition. that's why I spoke of designing an opsem that can be efficiently compiler (in all cases).</p>



<a name="187302014"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/re-visiting%20placement%20new/near/187302014" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/re-visiting.20placement.20new.html#187302014">(Feb 03 2020 at 20:45)</a>:</h4>
<blockquote>
<p>'d like us to get to the same point with carefully-written Rust: if you adhere to a few conventions while constructing large objects in otherwise natural ways (i.e., not rewriting everything to have explicit out-pointers), the stack should not blow up unless a whole sequence of very unlikely things happened.</p>
</blockquote>
<p>that still sounds somewhat unsatisfying though... something where no optimizations are needed but the structure of the code is such that in-place init is the natural way to compile things would be better, IMO. but this is an outsider opinion, I havent delved into all the hard questions here (nor do I have time to do that)</p>



<a name="187302538"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/re-visiting%20placement%20new/near/187302538" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/re-visiting.20placement.20new.html#187302538">(Feb 03 2020 at 20:50)</a>:</h4>
<p>I think we're actually in agreement, just approaching it from different directions. I'm also hedging my wording because no matter what we do, there will always be expressions that require huge temporaries to evaluate (but this should be predictable from examining the expression and the functions it calls), and there will also also expressions that run out of stack space despite being compiled in a way that does not involve any huge temporary (but e.g. perhaps a lot of small stack allocations that add up).</p>



<a name="187364591"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/re-visiting%20placement%20new/near/187364591" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/re-visiting.20placement.20new.html#187364591">(Feb 04 2020 at 14:52)</a>:</h4>
<p><span class="user-mention" data-user-id="124289">@rkruppe</span></p>
<blockquote>
<p>I think we're actually in agreement, just approaching it from different directions</p>
</blockquote>
<p>I can believe that :)</p>



<a name="187558659"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/re-visiting%20placement%20new/near/187558659" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Charles Lew <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/re-visiting.20placement.20new.html#187558659">(Feb 06 2020 at 15:38)</a>:</h4>
<p>I want to imagine there's a macro called <code>init!</code>, let me show it by example:<br>
assume we have</p>
<div class="codehilite"><pre><span></span>struct S{ a: u32 }
struct T { s: S, t: [u32; 5] }
fn foo(x: bool) -&gt; u32 { ... }
</pre></div>


<p>when there's a <code>let mut v = MaybeUninit::uninit();</code>, we can call<br>
<code>init!(v, T { s: S { a: f1 }, t: [f2; 5] }, f1 = foo(true), f2 = foo(false));</code> to fully initialize it.</p>
<p>the first parameter is a MaybeUninit&lt;T&gt;, the second parameter describes the "structure" of the init value, and the rest parameters are named parameters that got evaluated on the stack.</p>
<p>After this we can wrap it into a macro <code>box!(S {a: f1}, f1 = foo(true))</code> that provides the functionality of placement new and deprecate the box operator :)</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>